package com.bootdo.cash.controller;

import com.bootdo.cash.service.CashService;
import com.bootdo.cash.service.RecordService;
import com.bootdo.common.annotation.Log;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.order.domain.RechargeDO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Desc 充值记录
 * @date 2019/12/24
 *
 */
@Controller
@RequestMapping("/cash/record")
public class RecordController {

    private final String PREFIX = "cash/record";
    @Autowired
    private RecordService recordService;
    @Autowired
    private CashService cashService;

    @RequiresPermissions("cash:recode:record")
    @Log("充值记录")
    @GetMapping()
    String record(){
        return PREFIX + "/list";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("cash:recode:record")
    PageUtils list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<RechargeDO> list = recordService.list(query);
        int total = recordService.count(query);
        PageUtils pageUtils = new PageUtils(list, total);
        return pageUtils;
    }

    @RequiresPermissions("cash:recode:record")
    @Log("获取发起人备注")
    @PostMapping("/findUser")
    @ResponseBody
    R findUser(Long userId) {
        String name = cashService.findUser(userId);
        return R.ok(name);
    }
}
